package com.gxitsky.utils;

import org.apache.commons.lang3.RandomStringUtils;

/**
 * @author gxing
 * @desc TODO
 * @date 2022/5/7
 */
public class UidUtil {
    private static Long MILLIS = 0L;
    private static Long UID = 0L;

    /**
     * @desc 唯一id
     * @params length
     * @author gxing
     * @date 2021/9/25 23:33
     */
    public static Long getUID() {
        return getUID(2);
    }

    /**
     * @desc 唯一id
     * @params length
     * @author gxing
     * @date 2021/9/25 23:33
     */
    public static Long getUID(int length) {
        long millis = System.currentTimeMillis();
        if (millis == MILLIS) {
            UID++;
        } else {
            MILLIS = millis;
            String id = millis + "0" + RandomStringUtils.randomNumeric(length);
            UID = Long.valueOf(id);
        }
        return UID;
    }
}
